package com.shop.cereshop.admin.utils;

import org.springframework.stereotype.Component;

import java.time.LocalDateTime;
import java.time.ZoneId;

@Component
public class TimeUtil {

//    将localDateTime转换成时间戳的形式
    public  Long localDateTimeToTimestamp(LocalDateTime localDateTime) {
        return localDateTime.atZone(ZoneId.systemDefault()).toInstant().toEpochMilli();
    }

//    将String转换成localDateTime
    public  LocalDateTime stringToLocalDateTime(String date) {
        return LocalDateTime.parse(date);
    }

//    将时间戳转换成localDateTime
    public  LocalDateTime timestampToLocalDateTime(Long timestamp) {
        return LocalDateTime.ofInstant(java.time.Instant.ofEpochMilli(timestamp), ZoneId.systemDefault());
    }
}
